package com.carcontrol.myplugin4.base;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.carcontrol.myplugin4.utils.ToastUtils;

/**
 * 自定义Application
 * 
 * @author wutao
 *
 */
public class BaseApplication
		extends Application
//		extends MultiDexApplication
		{
	public static String mode = "";	//"t":改密钥密码模式 	"":正常模式

	public  static Context context;
	private static BaseApplication app;
	public static int width;
	public static int height;
	public static float density;


	public static int school_id;
	public static int school_id2;
	public static String school_name;
	public static String school_latitude = "";	//用户管辖城市纬度
	public static String school_longitude = "";	//用户管辖城市经度
	public static int[] school_carmodel_ids;


	private PackageInfo packageInfo;

	public BaseApplication() {
		app = this;
	}

	public static synchronized BaseApplication getInstance() {
		if (app == null) {
			app = new BaseApplication();
		}
		return app;
	}

//	@Override
//	protected void attachBaseContext(Context base) {
//		super.attachBaseContext(base);
//		MultiDex.install(this);
//	}

	@Override
	public void onCreate() {
		super.onCreate();

//		File dexPath = new File(getDir("dex", Context.MODE_PRIVATE), "path_dex.jar");
//		Log.e("mainHHH","dexPath = " + dexPath.getAbsolutePath());
//		Utils.prepareDex(getApplicationContext(), dexPath, "path_dex.jar");
//		HotFix.patch(getApplicationContext(), dexPath.getAbsolutePath(), "");

//





		DisplayMetrics metrics = new DisplayMetrics();
		WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(metrics);
		density = metrics.density;
		width = metrics.widthPixels;
		height = metrics.heightPixels;

//		SharedPreferencesUrls.getInstance().putString("access_token", "1");
		ToastUtils.init(this);



//		HotFix.patch(getApplicationContext());

//		try {
//			File patchDexDir = getDir(PATCH_DEX_PATH, Context.MODE_PRIVATE);
//			File optimizedFile = new File(patchDexDir, "optimized");
//			if (!optimizedFile.exists()) {
//				optimizedFile.mkdirs();
//			}
//
//			String path = "/data/data/com.fengmang.scouringpad/app_dex/classes2.dex";
////			File dex = getDir("dex", Context.MODE_PRIVATE);
//			DexClassLoader dexClassLoader = new DexClassLoader(path, optimizedFile.getAbsolutePath(), null, getClassLoader());
//
//            dexClassLoader.loadClass("com.fengmang.scouringpad.PersonInfoActivity");
////            dexClassLoader.loadClass("com.hongx.plugin.MainActivity2");
////
////            AssetManager manager = AssetManager.class.newInstance();
////            Method addAssetPath = AssetManager.class.getMethod("addAssetPath", String.class);
////            addAssetPath.invoke(manager, path);
////            resources = new Resources(manager, context.getResources().getDisplayMetrics(), context.getResources().getConfiguration());
////
//			Log.e("loadPath===1", "==="+dexClassLoader);
//		} catch (Exception e) {
//			Log.e("loadPath===e", "==="+e);
//		}
	}

	// 注册App异常崩溃处理器
	private void registerUncaughtExceptionHandler() {
		Thread.setDefaultUncaughtExceptionHandler(AppException.getAppExceptionHandler());
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
		System.gc();
	}

}
